import {action, observable, runInAction} from "mobx";
import {BaseResInterface, BaseResInterfaceWithData, sendGetRequest} from "../../../net";
import {
    SignInInfoAttribute,
    UserOutPointsInterface,
    UserVipInfoInterface
} from "../../../net/instance/CommenModelInstance";
import UserStoreInstance from "./index";
import {defaultArr} from "../../../util";


interface Sign {
    isSigned: boolean,
    current: Date
}

export class SignStore {
    @observable isAlreadySignIn: boolean = true;
    @observable signOutPointDetails: SignInInfoAttribute[] = defaultArr;


    @action.bound
    async checkUserIsSigned() {
        const {data} = await sendGetRequest<BaseResInterfaceWithData<Sign>>("user/checkAlreadySignIn", {userId: UserStoreInstance.user.id});
        runInAction(() => {
            this.isAlreadySignIn = data.isSigned;
        })
    }

    @action.bound
    async sendSignInRequest() {
        const res = await sendGetRequest<BaseResInterfaceWithData<number>>("user/signIn", {userId: UserStoreInstance.user.id});
        runInAction(() => {
            this.isAlreadySignIn = true;
        });
        return res;
    }


    @action.bound
    async getSignInDetails() {
        const {data} = await sendGetRequest<BaseResInterfaceWithData<SignInInfoAttribute[]>>("user/getSignInDetails", {userId: UserStoreInstance.user.id});
        runInAction(() => {
            this.signOutPointDetails = data;
        })
    }

}

const SignStoreInstance = new SignStore();
export default SignStoreInstance